<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>上传多个文件</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="features.file-upload.common-pitfalls.html">« 常见缺陷</a></li>
      <li style="float: right;"><a href="features.file-upload.put-method.html">对 PUT 方法的支持 »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="features.file-upload.html">文件上传处理</a></li>
    <li>上传多个文件</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="features.file-upload.multiple" class="sect1">
  <h2 class="title">上传多个文件</h2>
  <p class="simpara">
   可以对 <code class="literal">input</code> 域使用不同的 <code class="literal">name</code> 来上传多个文件。
  </p>
  <p class="simpara">
   PHP 支持同时上传多个文件并将它们的信息自动以数组的形式组织。要完成这项功能，需要在
   HTML 表单中对文件上传域使用和多选框与复选框相同的数组式提交语法。
  </p>
  <p class="para">
   <div class="example" id="example-456">
    <p><strong>示例 #1 上传多个文件</strong></p>
    <div class="example-contents">
<div class="htmlcode"><pre class="htmlcode">&lt;form action=&quot;file-upload.php&quot; method=&quot;post&quot; enctype=&quot;multipart/form-data&quot;&gt;
  Send these files:&lt;br /&gt;
  &lt;input name=&quot;userfile[]&quot; type=&quot;file&quot; /&gt;&lt;br /&gt;
  &lt;input name=&quot;userfile[]&quot; type=&quot;file&quot; /&gt;&lt;br /&gt;
  &lt;input type=&quot;submit&quot; value=&quot;Send files&quot; /&gt;
&lt;/form&gt;</pre>
</div>
    </div>

   </div>
  </p>
  <p class="simpara">
   当以上表单被提交后，数组
   <var class="varname"><a href="reserved.variables.files.html" class="classname">$_FILES['userfile']</a></var>，<var class="varname"><a href="reserved.variables.files.html" class="classname">$_FILES['userfile']['name']</a></var>
   和 <var class="varname"><a href="reserved.variables.files.html" class="classname">$_FILES['userfile']['size']</a></var> 将被初始化。
  </p>
  <p class="simpara">
   例如，假设名为 <var class="filename">/home/test/review.html</var> 和
   <var class="filename">/home/test/xwp.out</var> 的文件被提交，则
   <var class="varname"><a href="reserved.variables.files.html" class="classname">$_FILES['userfile']['name'][0]</a></var> 的值将是
   <var class="filename">review.html</var>，而
   <var class="varname"><a href="reserved.variables.files.html" class="classname">$_FILES['userfile']['name'][1]</a></var> 的值将是
   <var class="filename">xwp.out</var>。类似的，<var class="varname"><a href="reserved.variables.files.html" class="classname">$_FILES['userfile']['size'][0]</a></var>
   将包含文件 <var class="filename">review.html</var> 的大小，依此类推。
  </p>
  <p class="simpara">
   此外也同时设置了 <var class="varname"><a href="reserved.variables.files.html" class="classname">$_FILES['userfile']['name'][0]</a></var>，
   <var class="varname"><a href="reserved.variables.files.html" class="classname">$_FILES['userfile']['tmp_name'][0]</a></var>，
   <var class="varname"><a href="reserved.variables.files.html" class="classname">$_FILES['userfile']['size'][0]</a></var>
   以及 <var class="varname"><a href="reserved.variables.files.html" class="classname">$_FILES['userfile']['type'][0]</a></var>。
  </p>
  <div class="warning"><strong class="warning">警告</strong>
   <p class="simpara">
    The
    <a href="ini.core.html#ini.max-file-uploads" class="link">max_file_uploads</a>
    configuration setting acts as a limit on the number of files that can be
    uploaded in one request. You will need to ensure that your form does not
    try to upload more files in one request than this limit.
   </p>
  </div>
 </div></div></div></body></html>